<?php

class Workflow extends BaseModel
{

    public $xml;
	/**
	 * Returns the static model of the specified AR class.
	 * @return CActiveRecord the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'workflow';
	}

    public function rules()
    {
        return array(
            array('workflow_name, xml', 'required', 'message'=>'{attribute} 不能为空'),
            array('workflow_name', 'unique'),
        );
    }

    /**
     *
     * @return array customized attribute labels (name=>label)
     */
    public function attributeLabels()
    {
        return array(
            'workflow_id' => '编号',
            'workflow_name' => '工作流名称',
            'workflow_created' => '创建时间',
            'workflow_version' => '版本号',
            'xml'   => 'XML描述',
        );
    }
    
 	public static function listItems() 
    {
        $db = Task::model()->dbConnection;
        $command = $db->createCommand('select workflow_id, workflow_name from (select * from workflow order by workflow_id DESC, workflow_version DESC) t group by workflow_name');
        $workflows = $command->queryAll();
        return CHtml::listData($workflows, 'workflow_id', 'workflow_name');
    }

}
